extends Area2D

var skewTween:Tween

var scaleTween:Tween
var startScale:Vector2 = Vector2(1.0,1.0)
var endScale:Vector2 = Vector2(1.0,0.5)

var shader_tween: Tween



@onready var sprite_2d: Sprite2D = $Sprite2D



#func _ready() -> void:
	
	#var startSkew = deg_to_rad(randf_range(-10,-10))
	#var endSkew = -startSkew
#
	#skewTween = get_tree().create_tween().set_loops()
	#skewTween.tween_property(sprite_2d,"skew",endSkew,1.5).from(startSkew)
	#skewTween.tween_property(sprite_2d,"skew",startSkew,1.5).from(endSkew)
	#skewTween.set_ease(Tween.EASE_IN_OUT)
	#
	


func _on_body_entered(body: Node2D) -> void:
	CreateNewScaleTween(endScale,0.1)




func _on_body_exited(body: Node2D) -> void:
	CreateNewScaleTween(startScale,0.1)
	if shader_tween != null && shader_tween.is_valid():
		shader_tween.kill()
	
	shader_tween = create_tween()
	shader_tween.tween_property(sprite_2d.material, "shader_parameter/strength", 3, .2)\
		.from(1).set_trans(Tween.TRANS_QUINT).set_ease(Tween.EASE_IN)
	
	
	


func CreateNewScaleTween(targetValue:Vector2,duration:float):
	if scaleTween:
		scaleTween.kill()
	
	scaleTween = get_tree().create_tween()
	scaleTween.tween_property(sprite_2d,"scale",targetValue,duration)
	#skewTween.set_ease(Tween.EASE_IN_OUT)
	
	if shader_tween != null && shader_tween.is_valid():
		shader_tween.kill()
	
	shader_tween = create_tween()
	shader_tween.tween_property(sprite_2d.material, "shader_parameter/strength", 0, .2)\
		.from(1).set_trans(Tween.TRANS_QUINT).set_ease(Tween.EASE_IN)
	
	
	
